﻿/*
输入：
5 4
1 2
1 3
2 4
3 4
1 4
输出：
1
*/
// N个节点，M个边
string[] NMStr = Console.ReadLine().Split(" ");
int N = int.Parse(NMStr[0]);
int M = int.Parse(NMStr[1]);

// 构造并查集
int[] father = new int[N + 1];
for (int i = 1; i < father.Length; i++) // 初始化
{
    father[i] = i;
}

int find(int[] father, int u) // 寻根，路径压缩
{
    return father[u] == u ? u : father[u] = find(father, father[u]);
}

bool isSame(int[] father, int u, int v) // 判断是否在一个集合中
{
    u = find(father, u);
    v = find(father, v);
    return u == v;
}

void join(int[] father, int s, int t) // 加入集合
{
    int u = find(father, s);
    int v = find(father, t);
    if (u == v) return;
    father[u] = v;
}
for (int i = 0; i < M; i++)
{
    string[] st = Console.ReadLine().Split(" ");
    int s = int.Parse(st[0]);
    int t = int.Parse(st[1]);
    join(father, s, t);
}

// 传入开始、结尾
string[] pointStr = Console.ReadLine().Split(" ");
int source = int.Parse(pointStr[0]);
int destination = int.Parse(pointStr[1]);
bool res = isSame(father, source, destination);
Console.WriteLine(res ? 1 : 0);
